package main

import (
	"fmt"
	"runtime"
	"time"
)

func main() {
	go task1()
	go task2()
	ch <- 1

	for runtime.NumGoroutine() > 1 {
		time.Sleep(1 * time.Millisecond)
	}
}

var ch chan int = make(chan int)

func task1() {
	for {
		v := <-ch
		if v%2 == 1 {
			fmt.Println("g1:", v)
			v++
			time.Sleep(1 * time.Second)
		}
		ch <- v
	}
}

func task2() {
	for {
		v := <-ch
		if v%2 == 0 {
			fmt.Println("g2:", v)
			v++
			time.Sleep(1 * time.Second)
		}
		ch <- v
	}
}
